(function () {
    "use strict";
    let version = "1.0.0";
    let jQuery = function (selector) {
        return new jQuery.fn.init(selector);
    }
    jQuery.fn = jQuery.prototype = {
        constructor: jQuery,
        init: function (selector) {
            /*如果参数为假*/
            if (!selector) {
                return this;
            }
            /*如果参数是函数*/
            if ($.isFunction(selector)) {
                document.addEventListener("DOMContentLoaded", selector);
            }
            /*如果参数是字符串*/
            else if ($.isString(selector)) {
                if ($.isHTMLString(selector)) {
                    let ele = document.createElement('div');
                    ele.innerHTML = selector;
                    [].push.apply(this, ele.children);
                } else {
                    [].push.apply(this, document.querySelector(selector));
                }
            }
            /*如果参数是数组或者是伪数组*/
            else if ($.isArray(selector) || $.isLikeArray(selector)) {
                /*把selector中所有的元素一次添加到this中并且更新length*/
                [].push.apply(this, selector);
            } else {
                this[0] = selector;
                this.length = 1;
            }
        },
        eq(index) {
            return $(this.get(index));
        },
        get(index) {
            return index >= 0 ? this[index] : this[this.length + index];
        },
        first() {
            return this.eq(0);
        },
        last() {
            return this.eq(-1);
        },
        toArray() {
            return [].slice.call(this);
        }
    }

    /* 工具方法的处理 */
    /* jQuery插件机制 */
    jQuery.fn.extend = jQuery.extend = function () {
        for(let key in o){
            this[key] = o[key];
        }
    }

    jQuery.extend({
        isString:function(str){
            return typeof str == "string";
        },
        isFunction:function(fn){
            return typeof fn == "string";
        },
        isObject:function(obj){
            return typeof obj == "string";
        },
        isHTMLString:function(htmlStr){
            return htmlStr.charAt(0) == "<" &&htmlStr.charAt(htmlStr.length-1)==">" && htmlStr.length >= 3
        },
        isArrary:function(arr){
            if(Arrry.isArrary){
                return Array.isArray(arr);
            }else{
                return Object.prototype.toString.call(arr)=="[object.Array]";
            }
        },
        isLikeArray:function(likeArray){
            return typeof $.isObject(likeArray) && "length" in likeArr && likeArr.length-1 in likeArr;
        }
    });

    jQuery.extend({
        xxxx(){
            console.log("---");
            
        }
       
    })
    jQuery.fn.extend({
        css:function(){},
        text:function(){},
        html:function(){},
        xxxx
    })
    jQuery.fn.extend({
        on:function(type,handler){
            for(let i=0,len=this.length;i<len;i++){
                this[i].addEventListener(type,handler)
            }
        },
        click: function(handler) {
            this.on("click", handler);
        },
        mouseenter: function(handler) {
            this.on("mouseenter", handler);
        },
        mouseleave: function(handler) {
            this.on("mouseleave", handler);
        }
    })
    jQuery.fn.axtend({
        css(){},
        attr(){},
        addClass(){},
        removeClass(){},
        xxxx(){}
    })
    jQuery.fn.init.prototype = jQuery.fn;

    window.jQuery = window.$ = jQuery;
})()